package cc.spider.core.queue;

import cc.spider.exception.QueueNullPointException;
import cc.spider.model.TaskInfo;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * 默认阻塞队列
 */
public class DefaultTaskQueue implements ITaskQueue {
    private BlockingQueue<TaskInfo> stepQueue = new LinkedBlockingQueue<>();

    public DefaultTaskQueue() {

    }

    @Override
    public TaskInfo dequeue() {
        try {
            return stepQueue.take();
        } catch (InterruptedException e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public boolean enqueue(TaskInfo task) {
        try {
            stepQueue.put(task);
            return true;
        } catch (InterruptedException e) {
            e.printStackTrace();
            return false;
        }
    }
}
